/**
 * 药品相关信息
 */
import request from '@/utils/request';
import { registerSource } from '@/common/baseUrl.js';

/**
 * 药品查询
 * patientId	字符串	患者id，用于计算报销比例f
 * search	字符串	搜索条件：通用名、商品名、疾病
 * skip	可选，数字	存在时，跳过若干条结果
 * limit	可选，数字	存在时，限制结果长度
 * hospitalId	字符串	医院id
 */
export function getDrugs(data) {
  return request({
    url: `/baseDrugs`,
    params: data
  });
}

// 查询药品详情
export function getDrugsInfo(baseDrugId) {
  return request({
    url: `/drugs/` + baseDrugId
  });
}

// 查询药品三定信息
export function regularMedicationInfo(patientId) {
  return request({
    url: `/patient/${patientId}/regularMedicationInfo`
  });
}

// 编辑药品三定信息
export function regularMedicationInfoEdit(patientId, data) {
  return request({
    method: 'POST',
    url: `/patient/${patientId}/regularMedicationInfo`,
    data
  });
}

// 查询客户收件信息
export function receiverAddress(patientId) {
  return request({
    url: `/patients/${patientId}/receiverAddress`,
    params: {
      type: 3
    }
  });
}

// 创建个人保险订单
export function insurance_orders(data) {
  data.source = registerSource;
  return request({
    url: '/patients/insurance_orders',
    method: 'POST',
    data
  });
}

// 保险包详情查询
export function products(id) {
  return request({
    url: `/insurance_packages/${id}/products`
  });
}

/**
 *
 *
 * @export  查询会员用药需求
 * @param {string} patientId
 * @param {string} id
 * @return {Promise}
 */
export function getDefaultDrugs(patientId, orderId) {
  return request({
    url: `/patients/${patientId}/drugRequirements/saleDrug`,
    params: {
      catalogId: orderId
    }
  });
}

// 定药
export function orderDrug(patientId, data) {
  return request({
    url: `/patient/${patientId}/order/norule`,
    method: 'POST',
    data
  });
}

// 添加客户用药需求
export function drugRequirements(patientId, data) {
  return request({
    url: `/patients/${patientId}/drugRequirements`,
    method: 'POST',
    data
  });
}

// 保险投保回调后请求确认接口v2 (激活服务中的投保单)
export function activationOrder(insureOrderNo, data) {
  return request({
    url: `/v2/insurance_order/insure/${insureOrderNo}`,
    method: 'POST',
    data,
    noqs: true,
    headers: {
      'Content-Type': 'application/json'
    }
  });
}

// 首页获取服务包列表
export function getDrugOrder(patientId) {
  return request({
    url: `/orders?where=${encodeURIComponent(JSON.stringify({ patientId: patientId, channel: 15 }))}`,
    method: 'get'
  });
}
// 获取订单详情

export function getDrugOrderDetail(patientId, orderId) {
  return request({
    url: `/patient/${patientId}/order/${orderId}`,
    method: 'get'
  });
}

/**
 * @description - 支付
 */
export function orderPay(orderId, data) {
  return request({
    method: 'post',
    url: `/orders/${orderId}/pay`,
    data,
    noqs: true,
    headers: {
      'Content-Type': 'application/json'
    }
  });
}

/**
 * @description - 根据订单获取支付方式
 */
export function paymentMethod(orderId) {
  return request({
    method: 'GET',
    url: `/orders/${orderId}/paymentMethod`
  });
}

/**
 * @description - 查询服务单对应自提机构
 */
export function selfDelivery(id, params) {
  return request({
    method: 'GET',
    url: `/insuranceOrders/${id}/selfDelivery`,
    params
  });
}

/**
 * @description - 询患者应收运费
 */
export function getFreight(patientId, params) {
  return request({
    method: 'GET',
    url: `/patient/${patientId}/freight`,
    params
  });
}

export default {
  getDrugs,
  getDrugsInfo
};
